package com.example.api.controller;

import com.example.api.aspect.SystemControllerLog;
import com.example.api.model.entity.Driver;
import com.example.api.model.enums.ActionTypeEnum;
import com.example.api.model.support.RespBean;
import com.example.api.service.DriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "驾驶员管理")
@RestController
@RequestMapping("/api/driver")
public class DriverController {

    @Resource
    private DriverService driverService;

    @ApiOperation("添加驾驶员")
    @PostMapping("/")
    @SystemControllerLog(description = "添加驾驶员", actionType = ActionTypeEnum.CREATE)
    public RespBean save(@RequestBody Driver driver) {
        return driverService.save(driver);
    }

    @ApiOperation("查询驾驶员")
    @GetMapping("/")
    @SystemControllerLog(description = "查询驾驶员", actionType = ActionTypeEnum.QUERY)
    public List<Driver> findAll(String name) {
        return driverService.findAll(name);
    }

    @ApiOperation("根据id查询驾驶员")
    @GetMapping("/{id}")
    @SystemControllerLog(description = "根据id查询驾驶员", actionType = ActionTypeEnum.QUERY)
    public Driver findById(@PathVariable Integer id) {
        return driverService.findById(id);
    }

    @ApiOperation("删除驾驶员")
    @DeleteMapping("/{id}")
    @SystemControllerLog(description = "删除驾驶员", actionType = ActionTypeEnum.DELETE)
    public RespBean delete(@PathVariable Integer id) {
        return driverService.delete(id);
    }

    @ApiOperation("更新驾驶员")
    @PutMapping("/")
    @SystemControllerLog(description = "更新驾驶员", actionType = ActionTypeEnum.UPDATE)
    public RespBean update(@RequestBody Driver driver) {
        return driverService.update(driver);
    }

}
